﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("计算器");
    this->setMaximumSize(250,330);
    this->setMinimumSize(250,330);

    QFont f("仿宋", 12);
    ui->lineEditMain->setFont(f);

    QIcon con("D:/Qt/QtProject/04-Calc/del.png");
    ui->pushButton_del->setIcon(con);

    //设置按钮颜色

    ui->pushButton_equal->setStyleSheet("background: blue");

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_1_clicked()
{
    expression += "1";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_2_clicked()
{
    expression += "2";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_3_clicked()
{
    expression += "3";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_4_clicked()
{
    expression += "4";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_5_clicked()
{
    expression += "5";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_6_clicked()
{
    expression += "6";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_7_clicked()
{
    expression += "7";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_8_clicked()
{
    expression += "8";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_9_clicked()
{
    expression += "9";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_add_clicked()
{
    expression += "+";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_sub_clicked()
{
    expression += "-";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_star_clicked()
{
    expression += "*";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_divide_clicked()
{
    expression += "/";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_zero_clicked()
{
    expression += "0";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_left_clicked()
{
    expression += "(";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButton_right_clicked()
{
    expression += ")";
    ui->lineEditMain->setText(expression);
}


void Widget::on_pushButtonC_clicked()
{
    expression.clear();
    ui->lineEditMain->clear();
}


void Widget::on_pushButton_del_clicked()
{
    expression.chop(1);
    ui->lineEditMain->setText(expression);
}

